<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="com.webapp.model.Circle,com.webapp.model.Message, java.util.List" %>
<% 
	List messages =  (List)session.getAttribute("Messages");
	if(messages  == null)
		response.sendRedirect("Error.jsp");
%> 
<!-- include moo talk header file -->
<%@ include file="MooTalkHeader.jsp" %>

		<div id="site_content_text">
		<% 
				String x = request.getParameter("message"); 
				if(x != null) {
					if(x.equals("deleted")) {
						%>
							<p style="color:red;">
								Message Deleted!
							</p>
						<%
					}
					
					if(x.equals("sent")) {
						%>
							<p style="color:red;">
								Message Sent!
							</p>
						<%
					}
				}
			%>
			<h2>Create a New Message</h2>
			<form action="MessageNew.do" method="post">
				<table>
				<tr>
					<input type="hidden" value="<%=myUser.getUserId()%>" name="UserID"/>
					<td><strong>To: </strong><br/><input text"text" value="" name="TOID"/></td>
				</tr>
				<tr> 
					<td>
						<strong>Subject: </strong><br/><input text"text" value="" name="SUBJECT"/>
					</td>
				</tr>
				<tr> 
					<td>
						<strong>Message:</strong><br/>
						<textarea rows="5" cols="20" name="MESSAGE"></textarea><br/>
					</td>
				</tr>
					<td>
					<input class="btn" type="submit" value="New Message"/>
					</td>
				</table>
			</form>
			<h2>Recieved Messages</h2>
			<% for (int i = 0; i < messages.size(); i++) { %>
				<% if ( i % 2 == 0)  {%>
				<div class="even">
				<% }else if ( i % 2 == 1){ %>
				<div class="odd">
				<% } %>
				<!--  grid type layout -->
				<% Message message = (Message)messages.get(i); %>
					<table>
						<tr> 
							<td><strong>From:</strong></td>
							<td><%=message.getSender()%> on <%=message.getDate()%></td>
						</tr>
						<tr> 
							<td><strong>Subject:</strong></td>
							<td><%=message.getSubject()%></td>
						</tr>
						<tr> 
							<td><strong>Message:</strong></td>
							<td><%=message.getContent()%></td>
						</tr>
						<tr> 
							<td><form action="MessageNew.do" method="post">
							<textarea rows="4" cols="20" name="MESSAGE"></textarea><br/>
							<input type="hidden" value="<%=myUser.getUserId()%>" name="UserID"/>
							<input type="hidden" name="SUBJECT" value="<%=message.getSubject()%>"/>
							<input type="hidden" name="TOID" value="<%=message.getSender()%>"/>
							<input type="hidden" name="UserID" value="<%=myUser.getUserId()%>"/>
							<input type="submit" class="btn" value="Reply"/></form></td>
							<td><form action="MessageDelete.do" method="post"><input type="hidden" value="<%=myUser.getUserId()%>" name="UserID"/><input type="hidden" name="MSGID" value="<%=message.getMessageId()%>"/><br/><input type="submit" class="btn" value="Delete"/></form></td>
						</tr>
					</table>
			<% } %>
			</div>
		</div>
		
<!--  include moo talk footer file -->
<%@ include file="MooTalkFooter.jsp" %>
